﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

  <!--<xsl:param name="ToolsInformation"></xsl:param>
  <xsl:param name ="DocumentTitle"></xsl:param>
  <xsl:param name="CompanyName"></xsl:param>
  <xsl:param name="Support"></xsl:param>-->

  <xsl:template match="/Database">
    <html>
      <head>
        <link rel="StyleSheet" href="default.css" type="text/css" />
        <script language="javascript" type="text/javascript">
          // 设置FieldSet高度方法，支持IE浏览器、Firefox
          // 参数1：pTableID，FieldSet内部div或table的id
          // 参数2：pFieldSetID，FieldSet的ID
          // 参数3：pImageID，图片的ID，展开或收缩后更新图片SRC


          function FieldSetVisual( pTableID, pFieldSetID, pImageID )
          {
          var objTable = document.getElementById( pTableID ) ;
          var objFieldSet = document.getElementById( pFieldSetID) ;
          var objImage = document.getElementById( pImageID) ;
          if( objTable.style.visibility == 'visible' )
          {
          objTable.style.visibility = 'hidden' ;
          objFieldSet.style.height = "30px" ;
          objImage.src="img/plus.gif" ;
          }
          else
          {
          objTable.style.visibility = 'visible';
          var heightFieldSet = parseInt(objFieldSet.style.height.substr(0,objFieldSet.style.height.length-2)) ;
          var heightTable = parseInt(objTable.offsetHeight) ;
          objFieldSet.style.height = heightFieldSet + heightTable + "px" ;
          objImage.src="img/minus.gif" ;
          }
          }
        </script>

      </head>
      <body>

        <h3>数据库摘要</h3>
        <fieldset id="f1" >
          <legend>
            <img id="i1" src="img/minus.gif" onclick="FieldSetVisual('div1','f1','i1')" ></img> 第一部分：基本信息
          </legend>
          <div id="div1" style="visibility:visible">
            <ul>
              <li>
                名称：<xsl:value-of select="@Name"/>
              </li>
              <li>
                编号：<xsl:value-of select="@Id"/>
              </li>
              <li>
                创建日期：<xsl:value-of select="@CreateTime"/>
              </li>
              <li>
                所有者：<xsl:value-of select="@Owner"/>
              </li>
            </ul>
          </div>

        </fieldset>
        <br />
        <br />
        <fieldset id="f2" style="height:30px">
          <legend>
            <img id="i2" src="img/plus.gif" onclick="FieldSetVisual('div2','f2','i2')"></img> 第二部分：属性
          </legend>
          <div id="div2" style="visibility:hidden">
            <xsl:apply-templates select="Properties"></xsl:apply-templates>
          </div>
        </fieldset>
        <br />
        <br />

        <fieldset id="f3">
          <legend>
            <img id="i3" src="img/minus.gif" onclick="FieldSetVisual('div3','f3','i3')"> 第三部分：扩展属性</img>
          </legend>
          <div id="div3" style="visibility:visible">
            <xsl:apply-templates select="ExtendProperties"></xsl:apply-templates>
          </div>
        </fieldset>
        <br />
        <br />

        <fieldset id="f4">
          <legend>
            <img id="i4" src="img/minus.gif" onclick="FieldSetVisual('div4','f4','i4')"></img> 第四部分：文件组信息
          </legend>
          <div id="div4" style="visibility:visible">
            <xsl:apply-templates select="FileGroups"></xsl:apply-templates>
          </div>

        </fieldset>

        <br />
        <br />
        <fieldset id="f5">
          <legend>
            <img id="i5" src="img/minus.gif" onclick="FieldSetVisual('div5','f5','i5')"></img> 第五部分：日志文件
          </legend>
          <div id="div5" style="visibility:visible">
            <xsl:apply-templates select="LogFiles"></xsl:apply-templates>

          </div>
        </fieldset>
        <br />
        <br />

        <fieldset id="f6">
          <legend>
            <img id="i6" src="img/minus.gif" onclick="FieldSetVisual('div6','f6','i6')"></img> 第六部分：用户信息
          </legend>

          <div id="div6" style="visibility:visible">
            <xsl:apply-templates select="Users"></xsl:apply-templates>
          </div>
        </fieldset>
        <br />
        <br />

        <fieldset id="f7">

          <legend>
            <img id="i7" src="img/minus.gif" onclick="FieldSetVisual('div7','f7','i7')"></img> 数据库对象
          </legend>
          <div id="div7" style="visibility:visible">
            <table>
              <tr class="RowHeader">
                <td>
                  <h4>
                    <a href="tables.xml" target="_self">第七部分：表</a>
                  </h4>
                </td>
                <td>

                  <h4>
                    <a href="views.xml" target="_self">第八部分：视图</a>
                  </h4>
                </td>

              </tr>
              <tr>
                <td>
                  <xsl:apply-templates select="Tables"></xsl:apply-templates>
                </td>
                <td>
                  <xsl:apply-templates select="Views"/>
                </td>
              </tr>
              <tr class="RowHeader">
                <td>
                  <h4>
                    <a href="functions.xml" target="_self">第九部分：用户定义函数</a>
                  </h4>
                </td>
                <td>
                  <h4>
                    <a href="storeprocedures.xml" target="_self">第十部分：存储过程</a>
                  </h4>
                </td>
              </tr>

              <tr>
                <td>
                  <xsl:apply-templates select="UserFunctions"></xsl:apply-templates>

                </td>
                <td>
                  <xsl:apply-templates select="StoredProcedures"></xsl:apply-templates>


                </td>
              </tr>
            </table>

          </div>

        </fieldset>
        <br />
        <br />

      </body>
    </html>
  </xsl:template>

  <xsl:template match="Properties">
    <xsl:choose>
      <xsl:when test="@Count &gt; 0">
        <table>
          <tr class="RowHeader">
            <td>属性名</td>
            <td>属性值</td>
          </tr>
          <xsl:for-each select="Property">
            <tr>
              <td>
                <xsl:value-of select="Name"/>
              </td>
              <td>
                <xsl:value-of select="Value"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </xsl:when>
      <xsl:otherwise>
        没有相关的属性
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>
  <xsl:template match="ExtendProperties">
    <xsl:choose>
      <xsl:when test="@Count &gt; 0">
        <table>
          <tr class="RowHeader">
            <td>属性名</td>
            <td>属性值</td>
          </tr>
          <xsl:for-each select="Property">
            <tr>
              <td>
                <xsl:value-of select="Name"/>
              </td>
              <td>
                <xsl:value-of select="Value"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </xsl:when>
      <xsl:otherwise>
        没有相关的扩展属性
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="Tables">
    <ul>
      <xsl:for-each select="Table">
        <li>
          <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
  <xsl:template match="Views">
    <ul>
      <xsl:for-each select="View">
        <li>
          <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
  <xsl:template match="UserFunctions">
    <ul>
      <xsl:for-each select="Function">
        <li>
          <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>

  <xsl:template match="StoredProcedures">
    <ul>
      <xsl:for-each select="StoredProcedure">
        <li>
          <xsl:value-of select="Schema"/>.<xsl:value-of select="Name"/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>

  <xsl:template match="Users">
    <table>
      <tr class="RowHeader">
        <td>用户名</td>
        <td>登录名</td>
        <td>类别</td>
      </tr>
      <xsl:for-each select="User">
        <tr>
          <td>
            <xsl:value-of select="Name"/>
          </td>
          <td>
            <xsl:value-of select="LoginName"/>
          </td>
          <td>
            <xsl:value-of select="LoginType"/>
          </td>
        </tr>
      </xsl:for-each>

    </table>
  </xsl:template>

  <xsl:template match="FileGroups">
    默认文件组：<xsl:value-of select="Default"/>

    <table>
      <tr class="RowHeader">
        <td>名称</td>
        <td>文件数量</td>
        <td>是否默认</td>
        <td>是否只读</td>
      </tr>
      <xsl:for-each select="FileGroup">
        <tr>
          <td>
            <xsl:value-of select="Name"/>
          </td>
          <td>
            <xsl:value-of select="FilesCount"/>
          </td>

          <td>
            <xsl:value-of select="IsDefault"/>
          </td>

          <td>
            <xsl:value-of select="IsReadOnly"/>
          </td>
        </tr>

        <xsl:if test="FilesCount &gt; 0">
          <tr>
            <td></td>
            <td colspan="3">
              <table>
                <tr class="RowHeader">
                  <td>文件名</td>
                  <td>文件路径</td>
                </tr>
                <xsl:for-each select="Files/File">
                  <tr>
                    <td>
                      <xsl:value-of select="Name"/>
                    </td>
                    <td>
                      <xsl:value-of select="FileName"/>
                    </td>
                  </tr>
                </xsl:for-each>

              </table>
            </td>
          </tr>
        </xsl:if>

      </xsl:for-each>
    </table>


  </xsl:template>
  <xsl:template match="LogFiles">
    <table>
      <tr class="RowHeader">
        <td>名称</td>
        <td>文件名</td>
      </tr>
      <xsl:for-each select="LogFile">
        <tr>
          <td>
            <xsl:value-of select="Name"/>
          </td>
          <td>
            <xsl:value-of select="FileName"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>
